import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);

var _this = new Vue();

const store = new Vuex.Store({
	state: {
		userinfo: {}, //用户信息
		myPos: {

		}, // 我的位置
		taskMsgs: []
	},
	mutations: {
		setUserinfo(state, data) {
			state.userinfo = data;
		},
		setMyPos(state, data) {
			state.myPos = data;
		},
		setTaskMsgs(state, data) {
			state.taskMsgs = data;
		}
	},
	getters: {

	},
	actions: {
		async getMyLocation({
			commit
		}) {
			uni.getLocation({
				type: 'gcj02',
				success: res => {
					console.log('获取位置', res);
					commit('setMyPos', res)
					uni.$emit('locationGet')
				}
			});
		},
		async getRefillTask({commit}) {
			let res = await _this.$u.api._refillTask();
			commit('setTaskMsgs',res);
		},
	}
});

Vue.prototype.$store = store;
